<?
/**
* This is where all information of user stored
* @author Adesanto Asman
* @version 1.0
* @copyright Copyright (c)2007, Adesanto Asman
* @package UID
*/

/**
* DB settings
*
*/
define('_DB_USERID_COMPANY'     , "USERID_COMPANY");
define('_DB_USERID_HDR'         , "USERID_HDR");
define('_DB_USERID_DTL'         , "USERID_DTL");
define('_DB_USERID_POST_HDR'    , "USERID_POST_HDR");
define('_DB_USERID_POST_DTL'    , "USERID_POST_DTL");

require("UIDVars.php");

/**
* Extends UIDVars
* @package UIDMth
* @see UIDVars
*/
class UIDMth extends UIDVars{

	/**
	* init the UID
	*
	* @param  string  $UID        the user id which input from login page
	* @param  string  $compSel    selected company
	* @param  string  $connName   connection name
	* @param  string  $connPwd
	* @param  string  $connHost
	*
	*/
	function UIDMth( $UID, $compSel, $connName, $connPwd, $connHost){

		$this->UID = $UID;

		$Db = new Oracle;

		$Db->init($connName,
              $connPwd,
              $connHost,
              _NO_COMMENT);

		if ($Db->connect()) {

			$srcDbCompany		= _DB_USERID_COMPANY;
			$srcDbHdr		    = _DB_USERID_HDR;
			$srcDbDtl	      = _DB_USERID_DTL;
			$srcDbPosHdr		= _DB_USERID_POST_HDR;
			$srcDbPosDtl		= _DB_USERID_POST_DTL;

			/**
			* fetch user name, dept & pos
			*
			*/
			GlobalFetchers::fetchUserDetail($Db,
    			                            $UID,
    			                            $compSel,
    			                            $srcDbHdr,
    			                            $this->name,
    			                            $this->deptNm,
    			                            $this->deptPos);

			GlobalFetchers::fetchUserPrivs($Db,
    		                             $UID,
    		                             $compSel,
    		                             $srcDbDtl,
    		                             $this->privs,
    		                             $this->uMdl);
		}else{

		  Misc::usrDie("Error: DB connection failed");
		}
	}

	/**
	 * Return user' name
	 * @see UIDVars, $name
	 * @param void
	 * @return string
	 */
	function getName(){

		return $this->name;
	}

	/**
	 * Return user' ID
	 * @see UIDVars, $UID
	 * @param void
	 * @return string
	 */
	function getUID(){

		return $this->UID;
	}

	/**
	 * Return user' Position
	 * @see UIDVars, $pos
	 * @param void
	 * @return string
	 */
	function getPos(){

		return $this->pos;
	}

	/**
	 * Return user' IdDepartment
	 * @see UIDVars, $dept
	 * @param void
	 * @return string
	 */
	function getDept(){

		return $this->dept;
	}

	/**
	 * Return user' NameDepartment
	 * @see UIDVars, $deptNm
	 * @param void
	 * @return string
	 */
	function getDeptNm(){

		return $this->deptNm;
	}

	/**
	 * Return user' Group of Position
	 * @see UIDVars, $grpPos
	 * @param void
	 * @return string
	 */
	function getGrpPos(){

		return $this->grpPos;
	}

	/**
	 * Return user' Privilege of specified modul
	 * @see UIDVars, $uMdl
	 * @param string $modul the name of modul
	 * @param string $priv  the type of privilege
	 * @return string
	 */
	function getPrivs($modul,$priv){

		$idx  = array_search($modul, $this->uMdl);
		if(strlen($idx) > 0){

		  return $this->privs[$priv][$idx];
		}else{

		  return 0;
		}
	}

  /**
   * Return user' Privilege of specified modul number
   * @see UIDVars, $uMdl
   * @param string $modul the name of modul
   * @param string $priv  the type of privilege
   * @return string
   */
  function getPrivsByNumber($modulNumber,$priv){

    $idx  = array_search($modulNumber, $this->privs["LEVELMN"]);
    if(strlen($idx) > 0){

      return $this->privs[$priv][$idx];
    }else{

      return 0;
    }
  }

	/**
	 * Return the status of operation that needs to be check
	 * @see UIDVars, $status
	 * @param void
	 * @return boolean
	 */
	function getStatus(){

	  return $this->status;
	}
}

define('FLAG_GO'    , "GO");
define('FLAG_NOGO'  , "NO_GO");

?>